<?php
/**
  * Plugin Name: WP Breedables
  * Plugin URI: http://dazzlesoftware.org/
  * Description: A plugin that provides a WordPress web interface for secondlife breedables
  * Version: 3.8.9.5
  * Author: Dazzle Software
  * Author URI: http://dazzlesoftware.org/
  **/

/**
 * WP_Breedable
 *
 * Main Breedable Plugin Class
 *
 * @package WP Breedable
 */
class WP_Breedable {

	/**
	 * Start breedable on plugins loaded
	 */
	function WP_Breedable() {
		add_action( 'plugins_loaded', array( $this, 'breedable_init' ), 8 );
	}

	/**
	 * Takes care of loading up breedable
	 */
	function breedable_init() {
		// Previous to initializing
		do_action( 'breedable_pre_init' );

		// Initialize
		$this->breedable_start();
		$this->breedable_constants();
		$this->breedable_includes();
		$this->breedable_load();

		// Finished initializing
		do_action( 'breedable_init' );
	}

	/**
	 * Initialize the basic breedable constants
	 */
	function breedable_start() {
		// Set the core file path
		define( 'BREEDABLE_FILE_PATH', dirname( __FILE__ ) );

		// Define the path to the plugin folder
		define( 'BREEDABLE_DIR_NAME',  basename( BREEDABLE_FILE_PATH ) );

		// Define the URL to the plugin folder
		define( 'BREEDABLE_FOLDER',    dirname( plugin_basename( __FILE__ ) ) );
		define( 'BREEDABLE_URL',       plugins_url( '', __FILE__ ) );

		//load text domain
		load_plugin_textdomain( 'breedable', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );

		// Finished starting
		do_action( 'breedable_started' );
	}

	/**
	 * Setup the breedable core constants
	 */
	function breedable_constants() {
		// Define globals and constants used by wp-e-commerce
		require_once( BREEDABLE_FILE_PATH . '/includes/constants.php' );

		// Load the core constants
		breedable_core_constants();

		// Is WordPress Multisite
		breedable_core_is_multisite();

		// Which version of breedables
		breedable_core_constants_version_processing();

		// Table names and related constants
		breedable_core_constants_table_names();

		// Any additional constants can hook in here
		do_action( 'breedable_constants' );
	}

	/**
	 * Include the rest of breedable's files
	 */
	function breedable_includes() {
		require_once( BREEDABLE_FILE_PATH . '/includes/functions.php' );
		require_once( BREEDABLE_FILE_PATH . '/includes/installer.php' );
		
		if ( is_admin() ) // change for user perm check once we made the user role
		{
			include_once( BREEDABLE_FILE_PATH . '/includes/meta-functions.php' );
			include_once( BREEDABLE_FILE_PATH . '/includes/post-functions.php' );
			include_once( BREEDABLE_FILE_PATH . '/includes/taxonomies-functions.php' );
		}

		// Any additional file includes can hook in here
		do_action( 'breedable_includes' );
	}

	/**
	 * Setup the breedable core
	 */
	function breedable_load() {
		// Before setup
		do_action( 'breedable_pre_load' );

		// Setup the core breedable globals
		breedable_core_setup_globals();

		// Set page title array for important breedable pages
		breedable_core_load_page_titles();

		// breedable is fully loaded
		do_action( 'breedable_loaded' );
	}

	/**
	 * breedable Activation Hook
	 */
	function install() {
		global $wp_version;
		if((float)$wp_version < 3.0){
			 deactivate_plugins(plugin_basename(__FILE__)); // Deactivate ourselves
			 wp_die( __('Looks like you\'re running an older version of WordPress, you need to be running at least WordPress 3.0 to use WP Breedable', 'breedable'), __('WP Breedable not compatible', 'breedable'), array('back_link' => true));
			return;
		}
		define( 'BREEDABLE_FILE_PATH', dirname( __FILE__ ) );
		require_once( BREEDABLE_FILE_PATH . '/includes/installer.php' );
		$this->breedable_constants();
		breedable_install();

	}

	public function deactivate() {
		foreach ( wp_get_schedules() as $cron => $schedule ) {
			wp_clear_scheduled_hook( "breedable_{$cron}_cron_task" );
		}
	}
}

// Start breedable
$breedable = new WP_Breedable();

// Activation
register_activation_hook( __FILE__, array( $breedable, 'install' ) );
register_deactivation_hook( __FILE__, array( $breedable, 'deactivate' ) );
?>